<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="CHT模号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="chtMoldNum">
              <j-search-select-tag placeholder="请输入CHT模号" v-model="model.chtMoldNum" :dictOptions="dictOptions" @change="selectchange()"></j-search-select-tag>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="试模机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="trimmerNo">
              <a-input v-model="model.trimmerNo" placeholder="请输入试模机号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="生产机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionNumber">
              <a-input v-model="model.productionNumber" placeholder="请输入生产机号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="机台型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="machineModel">
              <a-input v-model="model.machineModel" placeholder="请输入机台型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="螺杆直径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="screwDiameter">
              <a-input v-model="model.screwDiameter" placeholder="请输入螺杆直径"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="螺杆种类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="screwType">
              <a-input v-model="model.screwType" placeholder="请输入螺杆种类"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="报价吨位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quotedTonnage">
              <a-input v-model="model.quotedTonnage" placeholder="请输入报价吨位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="实际吨位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actualTonnage">
              <a-input v-model="model.actualTonnage" placeholder="请输入实际吨位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="报价成型周期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quotedFormingCycle">
              <a-input v-model="model.quotedFormingCycle" placeholder="请输入报价成型周期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="目标成型周期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="aimFormingCycle">
              <a-input v-model="model.aimFormingCycle" placeholder="请输入目标成型周期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="实际成型周期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actualFormingCycle">
              <a-input v-model="model.actualFormingCycle" placeholder="请输入实际成型周期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="炮筒最大射出量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maximumBarrelOutput">
              <a-input v-model="model.maximumBarrelOutput" placeholder="请输入炮筒最大射出量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="射胶量百分比" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="injectionAmount">
              <a-input v-model="model.injectionAmount" placeholder="请输入射胶量百分比"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="料筒停留时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="barrelResidenceTime">
              <a-input v-model="model.barrelResidenceTime" placeholder="请输入料筒停留时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="容模尺寸(长宽高)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="volumeSize">
              <a-input v-model="model.volumeSize" placeholder="请输入容模尺寸(长宽高)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="机械手种类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manipulatorType">
              <a-input v-model="model.manipulatorType" placeholder="请输入机械手种类"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="模具温控箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="temperatureControlBox">
              <a-input v-model="model.temperatureControlBox" placeholder="请输入模具温控箱"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="模温机" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="moldTemperatureMachine">
              <a-input v-model="model.moldTemperatureMachine" placeholder="请输入模温机"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="手掌(EOAT)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eoat">
              <a-input v-model="model.eoat" placeholder="请输入手掌(EOAT)"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'YlInjectionMoldingInformationForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        dictOptions:[],
        testres:[],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 13 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/ylInjectionMoldingInformation/add",
          edit: "/ch/ylInjectionMoldingInformation/edit",
          queryById: "/ch/ylInjectionMoldingInformation/queryById",
          queryAllMoldNum: "ch/ylProjectInfo/queryAllMoldNum",
          queryByChtMoldNum: "/ch/ylProjectInfo/queryByChtMoldNum"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
      this.queryAllMoldNum();
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      queryAllMoldNum(){
        getAction(this.url.queryAllMoldNum).then((res)=>{
              if(res.success){
                this.testres = res.result;
                for(let i = 0;i<this.testres.length;i++){
                  this.dictOptions.push({text:this.testres[i],value:this.testres[i]})
                }
                console.log(this.testres);
              }
            })
      },
      selectchange(){
        console.log(this.model.chtMoldNum);
        getAction(this.url.queryByChtMoldNum,{chtMoldNum:this.model.chtMoldNum}).then((res)=>{
          if(res.success){
            console.log(res.result);
            this.moldBasicInformation = res.result.moldBasicInformation;
            console.log(this.moldBasicInformation);
            this.model.machineModel = this.moldBasicInformation.moldingMachineModel;
            this.model.screwDiameter = this.moldBasicInformation.suggestedMachineScrewDiameter
            this.model.screwType = this.moldBasicInformation.screwType
            this.model.quotedTonnage = this.moldBasicInformation.machineTonnage
            this.model.quotedFormingCycle = this.moldBasicInformation.moldingCycle
            this.model.maximumBarrelOutput = this.moldBasicInformation.maxVolumeOfBarrelShot
            this.model.injectionAmount = this.moldBasicInformation.injectionPercentage
            this.model.barrelResidenceTime = this.moldBasicInformation.barrelResidenceTime
            this.model.volumeSize = this.moldBasicInformation.injectionMoldingMachineSize
            this.model.manipulatorType = this.moldBasicInformation.manipulatorType
            this.model.temperatureControlBox = this.moldBasicInformation.tempControlBox
            this.model.moldTemperatureMachine = this.moldBasicInformation.moldTemperatureMachine
            this.$set(this.model,'eoat',this.moldBasicInformation.eoat);
          }
        })
       },
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>